<template lang="html">
    <div class="message">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-message"></i>&nbsp;设置平台收货地址</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div style="height:20px;"></div>
            <el-form label-width="150px" class="demo-ruleForm">
                <el-form-item label="平台收货名称：">
                    <el-input type="text" v-model="name" style="width:500px"></el-input>
                </el-form-item>
                <el-form-item label="平台收货联系方式：">
                    <el-input type="text" v-model="mobile" style="width:500px"></el-input>
                </el-form-item>
                <el-form-item label="平台收货地址(省)：">
                    <el-input type="text" v-model="province" style="width:500px"></el-input>
                </el-form-item>
                 <el-form-item label="平台收货地址(市)：">
                    <el-input type="text" v-model="city" style="width:500px"></el-input>
                </el-form-item>
                 <el-form-item label="平台收货地址(区)：">
                    <el-input type="text" v-model="district" style="width:500px"></el-input>
                </el-form-item>
                <el-form-item label="平台收货详细地址：">
                   <el-input type="text" v-model="address"></el-input>
                </el-form-item>
                <el-form-item label="平台邮编地址：">
                    <el-input type="text" v-model="zip_code" style="width:500px"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="postAddress()">保存</el-button>
                    <router-link to="/configuration/address"><el-button type="primary">返回</el-button></router-link>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
import {getAddress,postAddress} from '@/api/configuration/list'
    export default {
        name: "configaddedit",
        data() {
            return {
                index:0,//中英文切换
                forms:[],//地址数据
                lang:'',//中英文，zh中文、en英文
                name:'',
                mobile:'',
                province:'',
                district:'',
                city:'',
                address:'',
                zip_code:'',
            }
        },
        created(){
            if(this.$route.query.index || this.$route.query.index != ''){
                this.index = this.$route.query.index;
            } 
            if(this.index == 0){
                this.lang = 'en';
            }else if(this.index == 1){
                this.lang = 'zh';
            }
            // console.log(this.index);
            //获取平台地址
            this.getAddress();
        },
        mounted() {
            
        },
        methods: {
            //获取平台地址
            getAddress(){
                getAddress().then(res => {
                    this.forms = res.data[this.index];
                    this.name = this.forms.name;
                    this.mobile = this.forms.mobile;
                    this.province = this.forms.province;
                    this.district = this.forms.district;
                    this.city = this.forms.city;
                    this.address = this.forms.address;
                    this.zip_code = this.forms.zip_code;
                })
            },
            //提交，保证金
            postAddress(){
                if(this.name == ''){
                    this.$message({
                        message: '请输入平台收货名称',
                        type: 'warning'
                    });
                    return false;
                }
                if(this.mobile == ''){
                    this.$message({
                        message: '请输入平台收货联系方式',
                        type: 'warning'
                    });
                    return false;
                }
                if(this.province == ''){
                    this.$message({
                        message: '请输入平台收货地址省份',
                        type: 'warning'
                    });
                    return false;
                }
                if(this.district == ''){
                    this.$message({
                        message: '请输入平台收货地址城市',
                        type: 'warning'
                    });
                    return false;
                }
                if(this.city == ''){
                    this.$message({
                        message: '请输入平台收货地址地区',
                        type: 'warning'
                    });
                    return false;
                }
                if(this.address == ''){
                    this.$message({
                        message: '请输入平台收货详细地址',
                        type: 'warning'
                    });
                    return false;
                }
                if(this.zip_code == ''){
                    this.$message({
                        message: '请输入平台邮编地址',
                        type: 'warning'
                    });
                    return false;
                }
                //设置
                var params = {};
                params.lang = this.lang;
                params.name = this.name;
                params.mobile = this.mobile; 
                params.province = this.province;
                params.district = this.district;
                params.city = this.city;
                params.address = this.address;
                params.zipCode = this.zip_code;
                postAddress(params).then(res => {
                    // console.log(res);
                    if(res.code == 200){
                        this.$message({
                            message: '保存成功！',
                            type: 'success'
                        });
                        this.getMargin();//重新加载
                    }else {
                        this.$message.error('保存失败！');
                    }
                })
            },
        }
    }
</script>

<style lang="css" scoped>
.del {
    color: #f00;
}
</style>
